﻿@{
    ViewBag.Title = "公告管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 136.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $grid = $("#gridTable");
        $grid.jqGrid({
            url: "../../PublicInfoManage/Notice/GetPageListJson",
            datatype: "json",
            height: $(window).height() - 136.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'F_NewsId', hidden: true },
                {
                    label: '公告标题', name: 'F_FullHead', index: 'F_FullHead', width: 600, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return '<p style="color: ' + rowObject.FullHeadColor + ';">' + cellvalue + '</p>';
                    }
                },
                { label: '公告类别', name: 'F_Category', index: 'F_Category', width: 100, align: 'center' },
                {
                    label: "发布时间", name: "F_ReleaseTime", index: "F_ReleaseTime", width: 140, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
                    }
                },
                { label: '信息来源', name: 'F_SourceName', index: 'F_SourceName', width: 100, align: 'center' },
                { label: '阅读次数', name: 'PV', index: 'PV', width: 80, align: 'center' },
                {
                    label: "发布状态", name: "F_EnabledMark", index: "F_EnabledMark", width: 80, align: "center", autowidth: false,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return "<span class=\"label label-success\">已发布</span>";
                        } else {
                            return "<span class=\"label label-danger\">未发布</span>";
                        }
                    }
                }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'F_CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $grid.getGridParam('selrow');
            },
            gridComplete: function () {
                $grid.setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                FullHead: $("#txt_Keyword").val()
            }
            $grid.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加公告',
            url: '/PublicInfoManage/Notice/Form',
            width: "1000px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("F_NewsId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '修改公告',
                url: '/PublicInfoManage/Notice/Form?keyValue=' + keyValue,
                width: "1000px",
                height: "600px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("F_NewsId");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PublicInfoManage/Notice/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的公告！', 0);
        }
    }
    //公告类别
    function btn_category() {
        dialogOpen({
            id: "DataItemList",
            title: '公告分类',
            url: '/SystemManage/DataItemList/Index?ItemCode=NoticeCategory',
            width: "800px",
            height: "500px",
            btn: null
        });
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
        <div class="btn-group">
            <a id="lr-category" class="btn btn-default" onclick="btn_category()"><i class="fa fa-tags"></i>&nbsp;公告类别</a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
    <div id="gridPager"></div>
</div>

